package com.longxi.tianjintianbao.ui.presenter.oa;

import android.content.Intent;
import android.view.View;

import com.longxi.tianjintianbao.AppConst;
import com.longxi.tianjintianbao.R;
import com.longxi.tianjintianbao.ui.activity.oa.ChangeFormalActivity;
import com.longxi.tianjintianbao.ui.activity.oa.CopeWithActivity;
import com.longxi.tianjintianbao.ui.activity.oa.CostApplyActivity;
import com.longxi.tianjintianbao.ui.adapter.ReceiptListPagerAdapter;
import com.longxi.tianjintianbao.ui.base.BaseActivity;
import com.longxi.tianjintianbao.ui.base.BasePresenter;
import com.longxi.tianjintianbao.ui.fragment.repair.ReceiptListFragment;
import com.longxi.tianjintianbao.ui.view.oa.IReceiptListAtView;
import com.longxi.tianjintianbao.utils.MyUtils;

import java.util.ArrayList;
import java.util.List;

public class ReceiptListAtPresenter extends BasePresenter<IReceiptListAtView> {

    private String typeName = "";
    private String type = "";

    private ReceiptListPagerAdapter receiptListPagerAdapter;

    private void initVariable() {
        mCategoryList = new ArrayList<>();
        mCategoryList.add("处理中");
        mCategoryList.add("已处理");
    }

    //tab 标签页
    private List<String> mCategoryList;

    public List<String> getCategoryList() {
        if (mCategoryList == null) {
            mCategoryList = new ArrayList<>();
        }
        return mCategoryList;
    }

    public ReceiptListAtPresenter(BaseActivity context) {
        super(context);
    }

    public void setBar() {
        Intent intent = mContext.getIntent();
        typeName =intent.getStringExtra(AppConst.TYPENAME);
        type =intent.getStringExtra(AppConst.TYPE);
        mContext.setTitle(typeName);
        mContext.setTvLeft(MyUtils.getString(R.string.home));
        mContext.mTvRight.setVisibility(View.VISIBLE);
        mContext.setTvRight("添加");
        initVariable();
    }

    public void initViewPager(){
        receiptListPagerAdapter = new ReceiptListPagerAdapter(mContext.getSupportFragmentManager(), getCategoryList(), type);
        getView().getViewPager().setAdapter(receiptListPagerAdapter);
        getView().getViewPager().setOffscreenPageLimit(getCategoryList().size() - 1);
        getView().getTabLayout().setTabSpaceEqual(true);
        getView().getTabLayout().setViewPager(getView().getViewPager());
    }

    public void toApplyActivity() {
        Intent mainIntent;
        switch (type) {
            case "13":
                mainIntent = new Intent(mContext, CostApplyActivity.class);
                mainIntent.putExtra(AppConst.TYPENAME,typeName);
                mainIntent.putExtra(AppConst.TYPE,type);
                mContext.startActivityForResult(mainIntent, AppConst.IntentRequstCode.ACTIVITY_COST_APPLY);
                break;
            case "280":
                mainIntent = new Intent(mContext, CopeWithActivity.class);
                mainIntent.putExtra(AppConst.TYPENAME,typeName);
                mainIntent.putExtra(AppConst.TYPE,type);
                mContext.startActivityForResult(mainIntent, AppConst.IntentRequstCode.ACTIVITY_COPE_WITH);
                break;
            case "19":
                mainIntent = new Intent(mContext, ChangeFormalActivity.class);
                mainIntent.putExtra(AppConst.TYPENAME,typeName);
                mainIntent.putExtra(AppConst.TYPE,type);
                mContext.startActivityForResult(mainIntent, AppConst.IntentRequstCode.ACTIVITY_CHANGE_FORMAL);
                break;
        }
    }

    public void refreshFragmentUi(){
        ReceiptListFragment receiptListFragment = (ReceiptListFragment) receiptListPagerAdapter.getCurrentFragment();
        receiptListFragment.refreshReceiptList();
    }
}
